﻿using MbUnit.Framework;
using TimeStamper.DSL;

namespace TimeStamper.Tests
{
    [TestFixture]
    public class LexerFixtures
    {

        [Test]
        public void Can_Load_EOF_Token_While_Disregarding_WhiteSpace()
        {
            var lexer = new Lexer(new StringCharacterBuffer("  ", 3));
            Assert.AreEqual(TokenKind.EOF, lexer.GetNextToken().Kind);
        }

        [Test]
        public void Can_Load_To_Token()
        {
            var lexer = new Lexer(new StringCharacterBuffer("-", 3));
            Assert.AreEqual(TokenKind.TO, lexer.GetNextToken().Kind);
        }

        [Test]
        public void Can_Load_TO_Token_As_Keyword()
        {
            var lexer = new Lexer(new StringCharacterBuffer(" TO ", 1));
            Assert.AreEqual(TokenKind.TO, lexer.GetNextToken().Kind);
        }

        [Test]
        public void Can_Load_TOMMOROW_Token()
        {
            var lexer = new Lexer(new StringCharacterBuffer(" TOMMOROW ", 3));
            var token = lexer.GetNextToken();
            Assert.AreEqual(TokenKind.TOMMOROW, token.Kind);
        }

        [Test]
        public void Can_Load_NUMBER_Token()
        {
            var lexer = new Lexer(new StringCharacterBuffer("1234", 3));

            var token = lexer.GetNextToken();
            Assert.AreEqual(TokenKind.NUMBER, token.Kind);
            Assert.AreEqual(1234, int.Parse(token.Text));
        }

        [Test]
        public void Can_Load_MONTH_IDENTIFIER_Token()
        {
            var lexer = new Lexer(new StringCharacterBuffer("Jan", 3));

            var token = lexer.GetNextToken();
            Assert.AreEqual(TokenKind.MONTH_IDENTIFIER, token.Kind);
            Assert.AreEqual("JAN", token.Text);
        }

        [Test]
        public void Can_Load_DAY_IDENTIFIER_Token()
        {
            var lexer = new Lexer(new StringCharacterBuffer("monday", 3));

            var token = lexer.GetNextToken();
            Assert.AreEqual(TokenKind.DAY_IDENTIFIER, token.Kind);
            Assert.AreEqual("MONDAY", token.Text);
        }

        [Test]
        public void Can_Load_DAY_AND_MONTH_Token()
        {
            var lexer = new Lexer(new StringCharacterBuffer("day month", 3));

            var token = lexer.GetNextToken();
            Assert.AreEqual(TokenKind.DAY, token.Kind);

            token = lexer.GetNextToken();
            Assert.AreEqual(TokenKind.MONTH, token.Kind);
        }

        [Test]
        public void Can_Load_DATE_IDENTIFIER_Token()
        {
            var lexer = new Lexer(new StringCharacterBuffer("12/12/2008 12-12-2008", 3));

            var token = lexer.GetNextToken();
            Assert.AreEqual(TokenKind.DATE_IDENTIFIER, token.Kind);
            Assert.AreEqual("12/12/2008", token.Text);

            token = lexer.GetNextToken();
            Assert.AreEqual(TokenKind.DATE_IDENTIFIER, token.Kind);
            Assert.AreEqual("12-12-2008", token.Text);
        }
    }
}